<template>
  <el-container>
    <el-container>
      <el-form ref="ruleForm" :model="ruleForm" status-icon :rules="rules" label-width="200px" class="demo-ruleForm">

        <el-form-item label="购书申请Id" prop="applyId">
          <el-input v-model="ruleForm.applyId" />
        </el-form-item>
        <el-form-item label="*内容(选填)" prop="content">
          <el-input v-model="ruleForm.content" />
        </el-form-item>
        <el-form-item>
          <el-radio v-model="ruleForm.isPass" :label="true">同意</el-radio>
          <el-radio v-model="ruleForm.isPass" :label="false">不同意</el-radio>
        </el-form-item>

        <el-form-item>
          <el-button class="buttonFirst" type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-container>
  </el-container>
</template>

<script>
import userApi from '@/api/user'
export default {
  data() {
    return {
      ruleForm: {
        applyId: '', // 1397015604619927554为manager,1401827904761724930为财务
        content: '',
        isPass: true
      }

    }
  },
  methods: {
    isTruePass() {
      this.isPass = true
    },
    isFalsePass() {
      this.isPass = false
    },
    async  submitForm(formName) {
      // this.$emit('submit')
      await userApi.completeTask(this.ruleForm.applyId, this.ruleForm.isPass, this.ruleForm.content).then(
        resp => {
          if (resp.data.success === true) {
            this.$message({
              message: '恭喜你，成功了',
              type: 'success'
            })
            this.$emit('submit')
          } else {
            this.$message.error('错了哦，这是一条错误消息')
          }
        }
      )
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.el-form-item{
    width: 500px;
}
</style>
